package co.fitstart.mobile.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.GenericDaoSupport;

import co.fitstart.entity.credit.Credit;
import co.fitstart.entity.credit.CreditTransaction;
import co.fitstart.entity.user.User;
import co.fitstart.mobile.dao.support.CreditDaoSupport;
import co.fitstart.mobile.service.CreditService;

/**
 * 
 * @author Ysy
 *
 */
@Service("creditService")
public class CreditServiceImpl implements CreditService {

    @Autowired
    private GenericDaoSupport genericDaoSupport;

    @Autowired
    private CreditDaoSupport creditDaoSupport;

    /*
     * (non-Javadoc)
     * 
     * @see
     * co.fitstart.mobile.service.CreditService#listCreditStatement(co.fitstart.
     * entity.credit.Credit)
     */
    @SuppressWarnings("unchecked")
    public List<CreditTransaction> listCreditTransaction(Credit credit) {
        if (credit == null)
            return null;
        String querySentence = "FROM CreditTransaction creditTransaction WHERE creditTransaction.credit = :credit ORDER BY creditTransaction.createTime DESC";
        return genericDaoSupport.searchForList(querySentence, "credit", credit);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * co.fitstart.mobile.service.CreditService#load(co.fitstart.entity.user.
     * User)
     */
    public Credit generallyLoad(User user) {
        Credit credit = creditDaoSupport.generallyLoad(user);
        return credit;
    }
}
